package controllers

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-tool/db"
	"go-tool/db/orm_iray_proxy"
	"go-tool/services"
)

type Default struct {
	Key string
	Val string
}

func (ctrl *Default) Index(c *gin.Context) {
	obj := services.JobInfo{}
	c.JSON(200, gin.H{
		"message": obj.JobEachConstructScene(),
	})
}

func (ctrl *Default) Index1(c *gin.Context) {
	sqlStr := `SELECT Name job_id, DateCreated start_time, DateCreated submit_time, DateModified finished_time,
				Height as height, Width as width, Priority as priority,MaxIterations max_iterations, b.RenderTime render_time
				from jobs 
				LEFT JOIN job_snapshots b on b.JobID=jobs.UUID
				where b.RenderTime>0`
	var jobs []orm_iray_proxy.JobInfo
	num := 0
	err := db.DbLite.Select(&jobs, sqlStr)
	if err != nil {
		fmt.Printf("query failed, err:%v\n", err)
		return
	}
	for i := 0; i < len(jobs); i++ {
		if jobs[i].Insert() {
			num++
		}
	}
	c.JSON(200, gin.H{
		"job num": len(jobs),
		"success": num,
	})
}
